package zelix.gui.clickguis.kendall.components.impls;

import org.lwjgl.input.Mouse;
import zelix.gui.clickguis.kendall.components.Component;
import zelix.utils.hooks.visual.ColorUtils;
import zelix.utils.hooks.visual.RenderUtils;
import zelix.utils.hooks.visual.font.FontLoaders;
import zelix.value.BooleanValue;


public class KendallOption extends Component {
    public KendallButton parent;
    public int x;
    public BooleanValue value;
    public int y;
    boolean previousmouse = true;
    boolean mouse;
    public KendallOption(BooleanValue value,KendallButton parent){
        this.value = value;
        this.parent = parent;
    }
    @Override
    public void render(float x,float y,int mouseX, int mouseY){
        RenderUtils.drawBorderedRect(x,y,x+500/2,y+58/2,0,0,0xFF1F2022);
        FontLoaders.default14.drawString(this.value.getRenderName(),x+20/2f,y+5,0x99F5F5F7);
        if (this.value.getValue()){
            //TRUE
            RenderUtils.drawBorderedRect(x+20/2f,y+14,x+20/2f+24,y+23,1,  ColorUtils.rainbow(50), ColorUtils.rainbow(50));
            RenderUtils.drawBorderedRect(x+20/2f+15,y+15,x+20/2f+22,y+21,1, 0xFF181818,0xFF181818);
        }else{
            //false
            RenderUtils.drawBorderedRect(x+20/2f,y+14,x+20/2f+24,y+23,1, 0xFF2E3239,0xFF2E3239);
            RenderUtils.drawBorderedRect(x+20/2f+2,y+15,x+20/2f+9,y+21,1, 0XFFF5F5F7,0XFFF5F5F7);
        }

        if ( KendallButton.isButtonHovered(x+20/2f,y+13,x+20/2f+24,y+22,mouseX,mouseY)){

            if (!this.previousmouse && Mouse.isButtonDown((int) 0)) {
                this.previousmouse = true;
                this.mouse = true;
            }

            if (this.mouse) {

                this.value.setValue(!this.value.getValue());
                this.mouse = false;
            }

        }
        if (!Mouse.isButtonDown(0)) {
            this.previousmouse = false;
        }
    }

    @Override
    public void mouseClicked(int mouseX, int mouseY,int mouseButton) {


    }

    public static boolean isHovered(float x, float y, float x2, float y2, int mouseX, int mouseY) {
        if (mouseX >= x && mouseX <= x2 && mouseY >= y && mouseY <= y2) {
            return true;
        }

        return false;
    }

}
